﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using VNet.VisiSuite.Service.Proxy;
using VNet.VisiSuite.Service.Contact.Message.Base;
using VNet.VisiSuite.Common.Security;
using VNet.VisiSuite.Service.Contact.Message.Item;

namespace VNet.VisiSuite.VisiAdmin.Providers
{
    public class CellProvider
    {
        public static void GetCells(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new GetDataRequest
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Id = (int)e.Argument
                    };
                    e.Result = client.GetCells(request);
                }
            }
        }

        public static void InsertCell(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new SaveDataRequest<CellItem>
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Data = e.Argument as CellItem,
                    };
                    e.Result = client.InsertCell(request);
                }
            }
        }

        public static void UpdateCell(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new SaveDataRequest<CellItem>
                    {
                        Identity = UserTransportToken.UserIdentity,
                        Data = e.Argument as CellItem,
                    };
                    e.Result = client.UpdateCell(request);
                }
            }
        }

        public static void DeleteCell(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            e.Result = null;
            if (worker != null && worker.CancellationPending == false)
            {
                if (worker != null && worker.CancellationPending == false)
                {
                    var client = new VNetVisiSuiteContractClient();
                    var request = new DeleteDataRequest
                    {
                        Identity = UserTransportToken.UserIdentity,
                        DataId = (int)e.Argument,
                    };
                    e.Result = client.DeleteCell(request);
                }
            }
        }
    }
}
